$(function() {

	$('.comments-container').each(function() {
		var commentsList = $(this).find(".comments-list");
        $(this).find('.comment-form').keypress(function(e) {
            // Enter pressed?
            if(e.which == 10 || e.which == 13) {
				//alert ($('input').val());
                //this.form.submit();
				var domainIdVal = $(this).find(".domain-id").val();
				var postSidVal = $(this).find(".post-sid").val();
				var commentBodyVal = $(this).find(".comment-body").val();

				var commentJson = "{\"domainId\":\""+domainIdVal+"\", \"targetSid\":"+postSidVal+", \"body\":\""+commentBodyVal+"\"}";

				//var htmlText = "<div> Hello"+postSidVal+":"+commentBodyVal+"</div>";
				//commentsList.append(htmlText);
				
				submitComment(commentJson, commentsList);
            }
        });
    });

});

function submitComment(commentJson, container)
{
	$.ajax({
		type: "POST",
		url: "http://localhost/seednia-uiphp-nb/rspost.php/comment",
		dataType: 'json',
		data: commentJson,
		cache: false,
		// jsonData contains the inserted record with new SID
		success: function(jsonData){
			var htmlText = "<div> "+jsonData.body+" by "+jsonData.creatorSid+"</div>";
			container.append(htmlText);
		}
	});
}